<?php
Yii::import('bootstrap.widgets.TbMenu', true);

class ApiMenuWidget extends TbMenu
{
	public $type = TbMenu::TYPE_PILLS;

	public function init()
	{
		$user = Yii::app()->user->getModel(); /* @var $user User */
		$project = $this->getOwner()->projectName;
		$accessList = Yii::app()->params['accessList'];
		$items = array(
			'api/index' => '总述',
			'api/login' => '登录授权',
			'api/logout' => '注销授权',
			'|',
			'api/put' => '更新数据',
			'api/del' => '删除数据',
			'api/clean' => '清空索引',
			'api/rebuild' => '重建索引',
			'|',
			'api/search' => '普通搜索',
			'api/count' => '计数搜索',
			'api/hot' => '热门搜索',
			'api/suggest' => '搜索建议',
		);
		$this->items = array();
		foreach ($items as $route => $label) {
			if ($label === '|') {
				$this->items[] = $label;
			} elseif (!isset($accessList[$route]) || $user->hasAccess($project, $route)) {
				$this->items[] = array('label' => $label, 'url' => array($route));
			}
		}
		parent::init();
	}
}
